import java.util.Scanner;

public class code1 {
    //方法一：/10%10的方法
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int x = scan.nextInt();
        int count = 0;
        for(int i=1;i<=n;i++) {
            int j = i;
            if(j%10==x) {
                count++;
            }
            while(j/10!=0) {
                j/=10;
                if(j%10==x) {
                    count++;
                }
            }
        }
        System.out.print(count);
    }
    //方法二：转为字符串判断每个字符是否为x
    public static void main2(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int x = scan.nextInt();
        int count = 0;
        for(int i=1;i<=n;i++) {
            String s = i+"";
            for(int j=0;j<s.length();j++) {
                int c=s.charAt(j)-'0';//注意字符转数字要减字符'0'
                if(c==x) count++;
            }
        }
        System.out.print(count);
    }
}
